class Factory implements FruitObservable {
    private final List<FruitObserver> observers = new ArrayList<>();

    @Override
    public void addObserver(FruitObserver observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(FruitObserver observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers(String fruitType) {
        for (FruitObserver observer : observers) {
            observer.onFruitCreated(fruitType);
        }
    }

    public Fruit CreateFruit(String kind) {
        Fruit fruit = null;
        if ("A".equals(kind)) {
            fruit = new Apple();
        } else if ("B".equals(kind)) {
            fruit = new Banana();
        }

        if (fruit != null) {
            notifyObservers(kind); // 触发通知
        }
        return fruit;
    }
}